package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.common.utils.BeanUtils;
import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.manager.vo.brand.BrandDetailRespVo;
import com.atguigu.spzx.manager.vo.brand.BrandQueryRespVo;
import com.atguigu.spzx.manager.vo.brand.BrandSaveReqVo;
import com.atguigu.spzx.manager.vo.brand.BrandUpdateReqVo;
import com.atguigu.spzx.manager.entity.Brand;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * BrandServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2023/10/29
 */
@Service
public class BrandServiceImpl implements BrandService{

    @Autowired
    private BrandMapper brandMapper;

    /**
     * 分页查询
     * @param pageParam
     * @return
     */
    @Override
    public Page<BrandQueryRespVo> getBrandPage(Page<Brand> pageParam) {
        return brandMapper.getBrandPage(pageParam);
    }

    /**
     * 添加
     * @param reqVo
     * @return
     */
    @Override
    public void saveBrand(BrandSaveReqVo reqVo) {
        Brand brand = BeanUtils.toBean(reqVo, Brand.class);
        brandMapper.insert(brand);
    }

    /**
     * 修改
     * @param reqVo
     * @return
     */
    @Override
    public void updateBrandById(BrandUpdateReqVo reqVo) {
        Brand brand = BeanUtils.toBean(reqVo, Brand.class);
        brandMapper.updateById(brand);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public BrandDetailRespVo getBrandById(Long id) {
        Brand brand = brandMapper.selectById(id);
        return BeanUtils.toBean(brand, BrandDetailRespVo.class);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public void deleteBrandById(Long id) {
        brandMapper.deleteById(id);
    }

    /**
     * 查询所有品牌
     * @return
     */
    @Override
    public List<BrandQueryRespVo> getBrandList() {
        List<Brand> list = brandMapper.selectList(null);
        return BeanUtils.toBeanList(list,BrandQueryRespVo.class);
    }
}
